;
(function($, window) {
	var ScorePlugn = function(ele, opts) {
		this.$element = ele,
			this.defaults = {
				'box_count': 10,
				'fn_dClick': function(){}
			},
			this.options = $.extend({}, this.defaults, opts)
	}

	ScorePlugn.prototype = {
		init: function() {
			//增加主框样式
			this.$element.addClass('x_score_main');
			//初始化回调事件
			if(typeof(this.options.fn_dClick) != 'function') {
				this.options.fn_dClick = function() {};
			}
			//添加内容
			var str_div = '';
			for (var i = 0; i <= this.options.box_count; i++) {
				str_div += '<div id="id' + i + '" name="score_box" class="x_score_box">' + i + '</div>';
			}
			str_div += '<input type="hidden" id="score_value" value="0">';
			this.$element.append(str_div);
			//初始化事件
			this.initEvent();
		},
		initEvent: function() {
			var obj = this;
			$("div[name=score_box]").click(function() {
				var num = $(this).text();
				$("div[name=score_box]:lt("+num+")").addClass("x_score_active");
				$("div[name=score_box]:eq("+num+")").addClass("x_score_active");
				$("div[name=score_box]:gt("+num+")").removeClass("x_score_active");
 				$("#score_value").val(num)
				
				obj.options.fn_dClick(num);
			});
		},
		resetScoreBoxHeight: function() {
			var height = this.$element.children(":first").innerWidth();
			this.$element.children().css("line-height", height + "px");
		},
		getScore: function() {
			return $("#score_value").val();
		}
	}
	$.fn.score = function(options) {
		return new ScorePlugn(this, options);
	}
})(jQuery, window);
